/* var xbox = document.querySelector('.xbox');
var zoom = document.querySelector('.zoom');
var dbox = document.querySelector('.dbox');
var boxs = document.querySelector('.boxs');
xbox.addEventListener('mouseenter', function () {
    zoom.style.display = 'block';
    dbox.style.display = 'block';
})
xbox.addEventListener('mouseleave', function () {
    zoom.style.display = 'none';
    dbox.style.display = 'none';
})
xbox.addEventListener('mousemove', function (e) {

    var left = e.pageX - boxs.offsetLeft - zoom.offsetWidth / 2;
    var top = e.pageY - boxs.offsetTop - zoom.offsetHeight / 2;
    var XMAX = xbox.offsetWidth - zoom.offsetWidth;
    var YMAX = xbox.offsetHeight - zoom.offsetHeight;
    if (left <= 0) {
        left = 0
    } else if (left >= zoom.offsetWidth) {
        left = zoom.offsetWidth
    }
    if (top <= 0) {
        top = 0
    } else if (top >= zoom.offsetHeight) {
        top = zoom.offsetHeight
    }
    zoom.style.left = left + 'px';
    zoom.style.top = top + 'px';
    var img = document.querySelector('.dbox img');
    img.style.left = -2 * left + 'px';
    img.style.top = -2 * top + 'px';
}) */
//http://jx.xuzhixiang.top/ap/api/detail.php
var obj = new URLSearchParams(location.search);
var pid = obj.get('pid');
let api = 'http://jx.xuzhixiang.top/ap/api/detail.php';
var params = { id: pid };
axios.get(api, { params }).then((v) => {
    var obj = v.data.data;
    var str =
        `
    <div class="xbox">
          <img src="${obj.pimg}" />
          <div class="zoom"></div>
        </div>
        <div class="dbox">
            <img src="${obj.pimg}" />
        </div>
    `
    document.querySelector('.boxs').innerHTML = str;
    var st =
        `
    <div>${obj.pname}</div>
    `
    document.querySelector('.jie').innerHTML = st;
    var sr =
        `
    <p>
    <span class="jing">京&nbsp;东&nbsp;价</span>
    <span class="qian">￥${obj.pprice}</span>
    <span class="tong">降价通知</span>
</p>
<p>
    <span class="jing">促&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;销</span>
    <span class="man">满减</span>
    <span class="mei">每满6799元，可减1000元现金</span>
</p>
    `
    document.querySelector('.jia').innerHTML = sr;
}
)
var inp = document.querySelector('input');
var zeng = document.querySelector('.zeng')
var jian = document.querySelector('.jian')
inp.addEventListener('blur', function () {
    var value = inp.value;
    inp.value = value
})
zeng.addEventListener('click', function () {
    var value = inp.value;
    value++
    inp.value = value
})
jian.addEventListener('click', function () {
    var value = inp.value;
    value--
    if (value < 1) {
        value = 1
    }
    inp.value = value
})
//加入购物车
/*   接口地址：http://jx.xuzhixiang.top/ap/api/add-product.php
     接口请求方式：get
     接口参数：
          uid  用户id
          pid  商品id
          pnum  要添加的商品数量

     使用方式

          http://jx.xuzhixiang.top/ap/api/add-product.php?uid=1&pid=1&pnum=1
          服务器返回json数据

*/
var gou = document.querySelector('.gou')
async function fn() {
    let uid = localStorage.getItem('uid');
    let pnum = inp.value;
    let cartAddAPI = 'http://jx.xuzhixiang.top/ap/api/add-product.php';
    let { data } = await axios.get(cartAddAPI, { params: { uid, pnum, pid } })
    // console.log(data);
}